beginobjectscript; // talking object

// cell 0 - which building?

variables;

short i;

body;

beginstate INIT_STATE;
	if (town_block_bought(get_memory_cell(0)))
		kill_object(ME,1);
	break;

beginstate DEAD_STATE;
	break;

beginstate START_STATE; 
	break;

beginstate USE_STATE;
	//QW2
	if (gf(0,11) < 6) {
		dlog_init();
		dlog_set_text("You need to get permission from General Miranda before you can order for buildings to be rebuilt.",24,0);
		dlog_set_bottom_button(0,1);
		dlog_run_choice(1);
		end();
		}
	if ((gf(0,11) < 11) && (gf(0,22) >= 2)) {
		dlog_init();
		dlog_set_text("You decide not to make another building yet. You might need the resources for something else. Perhaps Miranda can help.",24,0);
		dlog_set_bottom_button(0,1);
		dlog_run_choice(1);
		end();
		}
	
	// normal stuff
	if ((coins_amount() < 25) && ((which_town() > 0) || (gf(0,22) >= 2))) {
		dlog_init();
		dlog_set_text("You don't have enough money to construct this building.",24,0);
		dlog_set_text("It would cost:",16,0);
		dlog_set_resources(0,0,0,0,25);
		dlog_set_text("You have:",16,0);
		dlog_set_resources(0,0,0,0,coins_amount());
		dlog_set_bottom_button(0,1);
		dlog_run_choice(1);
		end();
		}
	dlog_init();
	dlog_set_text("Would you like to construct this building?",24,0);
	
	if ((which_town() == 0) && (gf(0,22) < 2)) {
		dlog_set_text("The first two buildings are free.",16,0);
		dlog_set_text("You can create a stall (which is outdoors) or a building you can enter.",16,0);

		dlog_set_text("Make a Stall",24,1);
		dlog_set_text("Make a Building",24,1);
		dlog_set_text("Build Nothing Yet",24,1);
		
		i = dlog_run_choice(1);
		if (i == 3) {
			set_block_bought(get_memory_cell(0),0);
			inc_flag(0,22,1);
			kill_object(ME,1);
			}
		if (i == 4) {
			set_block_bought(get_memory_cell(0),1);
			inc_flag(0,22,1);
			kill_object(ME,1);
			}
		end();
		}
	dlog_set_text("It would cost:",16,0);
	dlog_set_resources(0,0,0,0,25);
	dlog_set_text("You have:",16,0);
	dlog_set_resources(0,0,0,0,coins_amount());
	dlog_set_text("Make a Stall",24,1);
	dlog_set_text("Make a Building",24,1);
	dlog_set_text("Build Nothing Yet",24,1);

	i = dlog_run_choice(1);
	if (i == 5) {
		set_block_bought(get_memory_cell(0),0);
		if (which_town() == 0)
			inc_flag(0,22,1);
		kill_object(ME,1);
			change_coins(-25,FALSE);
		}
	if (i == 6) {
		set_block_bought(get_memory_cell(0),1);
		if (which_town() == 0)
			inc_flag(0,22,1);
		kill_object(ME,1);
			change_coins(-25,FALSE);
		}

break;
